//
//  SISSHouseInfoView.m
//  SISSAPP
//
//  Created by 优房网 on 2017/7/27.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSHouseInfoView.h"
#import "SISSPassengerTakeLookDetailModel.h"

@interface SISSHouseInfoView ()

@property (weak, nonatomic)  UILabel *neighbourhoodLabel;
@property (weak, nonatomic)  UILabel *regionAndDetailLabel;
@property (weak, nonatomic)  UIView *horizontalLineOne;
@property (weak, nonatomic)  UIView *horizontalLineTwo;
@property (weak, nonatomic)  UIView *verticalLineOne;
@property (weak, nonatomic)  UIView *verticalLineTwo;
@property (weak, nonatomic)  UILabel *priceLabel;
@property (weak, nonatomic)  UILabel *houseTypeLabel;
@property (weak, nonatomic)  UILabel *areaLabel;
@property (weak, nonatomic)  UIView *tagsView;
@property (strong, nonatomic) NSArray *listTagLabels;
@property (weak, nonatomic)  UILabel *propertyLabel;
@property (weak, nonatomic)  UILabel *averagePriceLabel;
@property (weak, nonatomic)  UILabel *directionLabel;
@property (weak, nonatomic)  UILabel *buildYearLabel;
@property (weak, nonatomic)  UILabel *decorationLabel;
@property (weak, nonatomic)  UILabel *intentionFloorLabel;
@property (weak, nonatomic)  UILabel *housecodingLabel;
@property (weak, nonatomic)  UILabel *otherDescriptionLabel;
@property (weak, nonatomic)  UILabel *insertTimeLabel;

@property (weak, nonatomic)  UILabel *priceTitleLabel;
@property (weak, nonatomic)  UILabel *houseTypeTitleLabel;
@property (weak, nonatomic)  UILabel *areaTitleLabel;
@property (weak, nonatomic)  UILabel *propertyTitleLabel;
@property (weak, nonatomic)  UILabel *averagePriceTitleLabel;
@property (weak, nonatomic)  UILabel *directionTitleLabel;
@property (weak, nonatomic)  UILabel *buildYearTitleLabel;
@property (weak, nonatomic)  UILabel *decorationTitleLabel;
@property (weak, nonatomic)  UILabel *intentionFloorTitleLabel;
@property (weak, nonatomic)  UILabel *housecodingTitleLabel;
@property (weak, nonatomic)  UILabel *otherDescriptionTitleLabel;
@property (weak, nonatomic)  UILabel *insertTimeTitleLabel;

@end
@implementation SISSHouseInfoView

- (void)setTakeLookDetailModel:(SISSPassengerTakeLookDetailModel *)takeLookDetailModel {
    _takeLookDetailModel = takeLookDetailModel;
    
    self.neighbourhoodLabel.text = takeLookDetailModel.neighbourhood;
    self.regionAndDetailLabel.text = [NSString stringWithFormat:@"%@-%@",takeLookDetailModel.region,takeLookDetailModel.regionDetail];
    self.priceLabel.text = [NSString stringWithFormat:@"%@万",@(takeLookDetailModel.price)];
    self.houseTypeLabel.text = takeLookDetailModel.houseType;
    self.areaLabel.text = [NSString stringWithFormat:@"%@㎡",@(takeLookDetailModel.area)];
    
    NSArray<UIColor *> *labelCololors = @[COLOR(0x33B189), COLOR(0xF76D81), COLOR(0x8E7FFF), COLOR(0x59ABFD), COLOR(0xE46B00)];
    
    
    for (NSInteger i = 0; i < takeLookDetailModel.listTag.count; i++) {
        UILabel *label = self.listTagLabels[i];
        label.hidden = NO;
        label.layer.borderWidth = 1;
        label.text = [NSString stringWithFormat:@" %@ ",takeLookDetailModel.listTag[i].tag];
        NSInteger colorIndex = takeLookDetailModel.listTag[i].color - 1;
        label.layer.borderColor = labelCololors[colorIndex].CGColor;
        label.textColor = labelCololors[colorIndex];
        label.layer.cornerRadius = 2;
        label.layer.masksToBounds = YES;
    }
    
    self.propertyLabel.text = takeLookDetailModel.propertyState;
    self.averagePriceLabel.text = [NSString stringWithFormat:@"%.0f元/㎡",takeLookDetailModel.averagePrice * 10000];
    self.directionLabel.text = takeLookDetailModel.direction ? takeLookDetailModel.direction : @"暂无数据";
    self.buildYearLabel.text = takeLookDetailModel.year ? [NSString stringWithFormat:@"%zd年",takeLookDetailModel.year] : @"暂无数据";
    self.decorationLabel.text = takeLookDetailModel.decoration.length ? takeLookDetailModel.decoration : @"暂无数据";
    NSArray *floorsArr = @[@"1-10层", @"11-20层", @"21-30层", @"30层以上"];
    self.intentionFloorLabel.text = takeLookDetailModel.floor ? floorsArr[takeLookDetailModel.floor/11] : @"暂无数据";
    self.housecodingLabel.text = takeLookDetailModel.houseInfoNo;
    self.otherDescriptionLabel.text = takeLookDetailModel.otherdesc.length ? takeLookDetailModel.otherdesc : @"暂无数据";
    self.insertTimeTitleLabel.text = @"看房时间";
    self.insertTimeLabel.text = [takeLookDetailModel.takeLookDate substringToIndex:10];
}


#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    self.backgroundColor = [UIColor whiteColor];
    
    UILabel *neighbourhoodLabel = [UILabel yyr_labelWithText:@"新洲花园" fontSize:20 textColor:MAIN_TEXT_COLOR];
    neighbourhoodLabel.font = [UIFont boldSystemFontOfSize:20];
    [self addSubview:neighbourhoodLabel];
    self.neighbourhoodLabel = neighbourhoodLabel;
    
    UILabel *regionAndDetailLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:regionAndDetailLabel];
    self.regionAndDetailLabel = regionAndDetailLabel;
    
    UIView *horizontalLineOne = [[UIView alloc] init];
    horizontalLineOne.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self addSubview:horizontalLineOne];
    self.horizontalLineOne = horizontalLineOne;
    
    UIView *horizontalLineTwo = [[UIView alloc] init];
    horizontalLineTwo.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self addSubview:horizontalLineTwo];
    self.horizontalLineTwo = horizontalLineTwo;
    
    UIView *verticalLineOne = [[UIView alloc] init];
    verticalLineOne.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self addSubview:verticalLineOne];
    self.verticalLineOne = verticalLineOne;
    
    UIView *verticalLineTwo = [[UIView alloc] init];
    verticalLineTwo.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self addSubview:verticalLineTwo];
    self.verticalLineTwo = verticalLineTwo;
    
    UILabel *priceTitleLabel = [UILabel yyr_labelWithText:@"售价" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:priceTitleLabel];
    self.priceTitleLabel = priceTitleLabel;
    
    UILabel *priceLabel = [UILabel yyr_labelWithText:@"--" fontSize:17 textColor:COLOR(0xFF6286)];
    [self addSubview:priceLabel];
    self.priceLabel = priceLabel;
    
    UILabel *houseTypeTitleLabel = [UILabel yyr_labelWithText:@"户型" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:houseTypeTitleLabel];
    self.houseTypeTitleLabel = houseTypeTitleLabel;
    
    UILabel *houseTypeLabel = [UILabel yyr_labelWithText:@"--" fontSize:17 textColor:COLOR(0xFF6286)];
    [self addSubview:houseTypeLabel];
    self.houseTypeLabel = houseTypeLabel;
    
    UILabel *areaTitleLabel = [UILabel yyr_labelWithText:@"面积" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:areaTitleLabel];
    self.areaTitleLabel = areaTitleLabel;
    
    UILabel *areaLabel = [UILabel yyr_labelWithText:@"--" fontSize:17 textColor:COLOR(0xFF6286)];
    [self addSubview:areaLabel];
    self.areaLabel = areaLabel;
    
    UIView *tagView = [[UIView alloc] init];
    [self addSubview:tagView];
    self.tagsView = tagView;
    
    NSMutableArray *tagLabelsArr = [NSMutableArray arrayWithCapacity:5];
    for (NSInteger i = 0; i < 5; i++) {
        UILabel *label = [[UILabel alloc] init];
        label.text = [NSString stringWithFormat:@"%d",arc4random_uniform(1000)];
        label.font = [UIFont systemFontOfSize:12];
        [tagView addSubview:label];
        
        UILabel *lastLabel;
        if (i > 0) {
            lastLabel = tagLabelsArr[i - 1];
        }
        
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            if (i == 0) {
                make.left.equalTo(tagView);
            } else {
                make.left.equalTo(lastLabel.mas_right).offset(4);
            }
            make.centerY.equalTo(tagView);
        }];
        label.hidden = YES;
        [tagLabelsArr addObject:label];
    }
    self.listTagLabels = tagLabelsArr.copy;
    
    UILabel *propertyTitleLabel = [UILabel yyr_labelWithText:@"产权：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:propertyTitleLabel];
    self.propertyTitleLabel = propertyTitleLabel;
    
    UILabel *propertyLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:propertyLabel];
    self.propertyLabel = propertyLabel;
    
    UILabel *averagePriceTitleLabel = [UILabel yyr_labelWithText:@"均价：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:averagePriceTitleLabel];
    self.averagePriceTitleLabel = averagePriceTitleLabel;
    
    UILabel *averagePriceLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:averagePriceLabel];
    self.averagePriceLabel = averagePriceLabel;
    
    UILabel *directionTitleLabel = [UILabel yyr_labelWithText:@"朝向：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:directionTitleLabel];
    self.directionTitleLabel = directionTitleLabel;
    
    UILabel *directionLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:directionLabel];
    self.directionLabel = directionLabel;
    
    UILabel *buildYearTitleLabel = [UILabel yyr_labelWithText:@"建筑年代：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:buildYearTitleLabel];
    self.buildYearTitleLabel = buildYearTitleLabel;
    
    UILabel *buildYearLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:buildYearLabel];
    self.buildYearLabel = buildYearLabel;
    
    UILabel *decorationTitleLabel = [UILabel yyr_labelWithText:@"装修程度：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:decorationTitleLabel];
    self.decorationTitleLabel = decorationTitleLabel;
    
    UILabel *decorationLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:decorationLabel];
    self.decorationLabel = decorationLabel;
    
    UILabel *intentionFloorTitleLabel = [UILabel yyr_labelWithText:@"楼层区间：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:intentionFloorTitleLabel];
    self.intentionFloorTitleLabel = intentionFloorTitleLabel;
    
    UILabel *intentionFloorLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:intentionFloorLabel];
    self.intentionFloorLabel = intentionFloorLabel;
    
    UILabel *housecodingTitleLabel = [UILabel yyr_labelWithText:@"房源信息编码：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:housecodingTitleLabel];
    self.housecodingTitleLabel = housecodingTitleLabel;
    
    UILabel *housecodingLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:housecodingLabel];
    self.housecodingLabel = housecodingLabel;
    
    UILabel *otherDescriptionTitleLabel = [UILabel yyr_labelWithText:@"其他需求说明：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:otherDescriptionTitleLabel];
    self.otherDescriptionTitleLabel = otherDescriptionTitleLabel;
    
    UILabel *otherDescriptionLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:otherDescriptionLabel];
    self.otherDescriptionLabel = otherDescriptionLabel;
    
    UILabel *insertTimeTitleLabel = [UILabel yyr_labelWithText:@"发布时间：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:insertTimeTitleLabel];
    self.insertTimeTitleLabel = insertTimeTitleLabel;
    
    UILabel *insertTimeLabel = [UILabel yyr_labelWithText:@"--" fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:insertTimeLabel];
    self.insertTimeLabel = insertTimeLabel;
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    WeakSelf
    CGFloat margin = 8.0;
    [self.neighbourhoodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(weakSelf).offset(3 * margin);
    }];
    
    [self.regionAndDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.neighbourhoodLabel.mas_right).offset(margin);
        make.bottom.equalTo(weakSelf.neighbourhoodLabel);
    }];
    
    [self.horizontalLineOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.neighbourhoodLabel);
        make.top.equalTo(weakSelf.neighbourhoodLabel.mas_bottom).offset(3 * margin);
        make.right.equalTo(weakSelf).offset(-3 * margin);
        make.height.mas_equalTo(1);
    }];
    
    [self.verticalLineOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.horizontalLineOne.mas_bottom).offset(2 * margin);
        make.centerX.equalTo(weakSelf).multipliedBy(0.7);
        make.height.mas_equalTo(60);
        make.width.mas_equalTo(1);
    }];
    
    [self.verticalLineTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.horizontalLineOne.mas_bottom).offset(2 * margin);
        make.centerX.equalTo(weakSelf).multipliedBy(1.3);
        make.height.mas_equalTo(60);
        make.width.mas_equalTo(1);
    }];
    
    [self.horizontalLineTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.height.width.equalTo(weakSelf.horizontalLineOne);
        make.top.equalTo(weakSelf.verticalLineOne.mas_bottom).offset(2 * margin);
    }];
    
    [self.priceTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.neighbourhoodLabel);
        make.top.equalTo(weakSelf.horizontalLineOne.mas_bottom).offset(2.5 * margin);
    }];
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.priceTitleLabel);
        make.top.equalTo(weakSelf.priceTitleLabel.mas_bottom).offset(margin);
    }];
    
    [self.houseTypeTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.priceTitleLabel);
        make.left.equalTo(weakSelf.verticalLineOne.mas_right).offset(2 * margin);
    }];
    
    [self.houseTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.houseTypeTitleLabel);
        make.centerY.equalTo(weakSelf.priceLabel);
    }];
    
    [self.areaTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.priceTitleLabel);
        make.left.equalTo(weakSelf.verticalLineTwo.mas_right).offset(2 * margin);
    }];
    
    [self.areaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.areaTitleLabel);
        make.centerY.equalTo(weakSelf.priceLabel);
    }];
    
    [self.tagsView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.neighbourhoodLabel);
        make.top.equalTo(weakSelf.horizontalLineTwo.mas_bottom).offset(2 * margin);
        make.right.equalTo(weakSelf).offset(-2 * margin);
        make.height.mas_equalTo(24);
    }];
    
    [self.propertyTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.neighbourhoodLabel);
        make.top.equalTo(weakSelf.tagsView.mas_bottom).offset(2 * margin);
    }];
    
    [self.averagePriceTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.propertyTitleLabel);
        make.top.equalTo(weakSelf.propertyTitleLabel.mas_bottom).offset(2 * margin);
    }];
    
    [self.directionTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.averagePriceTitleLabel);
        make.top.equalTo(weakSelf.averagePriceTitleLabel.mas_bottom).offset(2 * margin);
    }];
    
    [self.buildYearTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.directionTitleLabel);
        make.top.equalTo(weakSelf.directionTitleLabel.mas_bottom).offset(2 * margin);
    }];
    
    [self.decorationTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.propertyTitleLabel);
        make.top.equalTo(weakSelf.buildYearTitleLabel.mas_bottom).offset(2 * margin);
    }];
    
    [self.intentionFloorTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.propertyTitleLabel);
        make.top.equalTo(weakSelf.decorationTitleLabel.mas_bottom).offset(2 * margin);
    }];
    
    [self.housecodingTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.propertyTitleLabel);
        make.top.equalTo(weakSelf.intentionFloorTitleLabel.mas_bottom).offset(2 * margin);
    }];
    
    [self.otherDescriptionTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.buildYearTitleLabel);
        make.top.equalTo(weakSelf.housecodingTitleLabel.mas_bottom).offset(2 * margin);
    }];
    
    
    
    [self.propertyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.propertyTitleLabel.mas_right).offset(10 * margin);
        make.centerY.equalTo(weakSelf.propertyTitleLabel);
    }];
    
    [self.averagePriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.propertyLabel);
        make.centerY.equalTo(weakSelf.averagePriceTitleLabel);
    }];
    
    [self.directionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.propertyLabel);
        make.centerY.equalTo(weakSelf.directionTitleLabel);
    }];
    
    [self.buildYearLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.propertyLabel);
        make.centerY.equalTo(weakSelf.buildYearTitleLabel);
    }];
    
    [self.decorationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.propertyLabel);
       make.centerY.equalTo(weakSelf.decorationTitleLabel);
    }];
    
    [self.intentionFloorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.propertyLabel);
        make.centerY.equalTo(weakSelf.intentionFloorTitleLabel);
    }];
    
    [self.housecodingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.propertyLabel);
        make.centerY.equalTo(weakSelf.housecodingTitleLabel);
    }];
    
    [self.otherDescriptionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.otherDescriptionTitleLabel).offset(0.5 * margin);
        make.top.equalTo(weakSelf.otherDescriptionTitleLabel.mas_bottom).offset(margin);
    }];
    
    [self.insertTimeTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.otherDescriptionTitleLabel);
        make.top.equalTo(weakSelf.otherDescriptionLabel.mas_bottom).offset(2 * margin);
        make.bottom.equalTo(weakSelf).offset(-margin);
    }];
    
    [self.insertTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.propertyLabel);
        make.centerY.equalTo(weakSelf.insertTimeTitleLabel);
    }];
}


@end
